﻿using System;
using Microsoft.WindowsAzure.StorageClient;

namespace LCA.Community.DAL.Model
{
    /// <summary>
    /// This class contains a single pair of user and group.
    /// 
    /// PartitionKey = ID of the group.
    /// </summary>
    public class GroupMembership : BasicDataModel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="GroupMembership"/> class.
        /// </summary>
        public GroupMembership()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="GroupMembership"/> class.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="group">The group.</param>
        public GroupMembership(string user, string group)
        {
            RowKey = Guid.NewGuid().ToString();
            PartitionKey = group;
            Member = user;
        }

        /// <summary>
        /// Gets or sets the group
        /// </summary>
        /// <value>The group.</value>
        public string Group 
        { 
            get
            {
                return PartitionKey;
            }
            set
            {
                PartitionKey = value;
            }
        }
        /// <summary>
        /// Gets or sets the gruop's member.
        /// </summary>
        /// <value>The group's member.</value>
        public string Member { get; set; }
        /// <summary>
        /// Equalses the specified obj.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <returns><c>true</c> if both objects are equals; otherwise, <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            GroupMembership u = obj as GroupMembership;
            if ((System.Object)u == null)
            {
                return false;
            }

            return RowKey.Equals(u.RowKey);

        }
        /// <summary>
        /// Gets the hash code.
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
